package br.com.gsc.model.tableMapping;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.springframework.transaction.annotation.Transactional;

@Entity
//@Table(name="operators")
@Transactional
public class Operator extends Person {

	private String codigo;
	 
	 @ManyToMany(cascade = CascadeType.ALL)
	 @JoinTable(name = "PRODUCT_OPERATOR",
				joinColumns = @JoinColumn(name = "username"),
				inverseJoinColumns = @JoinColumn(name = "product_id"))
     private List<Product> listOfProducts = new ArrayList<Product>();		
	
	public Operator(){
		super(RoleUserType.OPER_ROLE);
	}
	
	public List<Product> getListOfProducts() {
		return listOfProducts;
	}

	public void setListOfProducts(List<Product> listOfProducts) {
		this.listOfProducts = listOfProducts;
	}
	
	public void addProduct(Product prod){
		this.listOfProducts.add(prod);
	}		
	public void removeProduct(Product prod){
		this.listOfProducts.remove(prod);
	}
	
}
